<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

    <div style="height: 47px"></div>
    <BreakSpace label="操作记录" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable ref="table" :columns="columnsLog" :dataSource="tableList" :onColumnsChange="columns => (this.columnsLog = columns)" :isSelectColumn="false"></FilterTable>
    <div style="height: 47px"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">返 回</el-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
import { queryById, queryRecordById } from '@/api/dealerSale/TestDrive/query';

export default {
  name: 'addModel',
  props: ['rowData'], // 上个页面带入的值
  data() {
    this.saveData = null;
    this.BaseTable = null;
    return {
      formList: this.createdFrom(),
      columnsLog: this.createdLogTable(),
      tableList: [],
      fromData: {}
    };
  },
  created() {
    this.init();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  mixins: [dictionary],
  methods: {
    init() {
      this.queryByIdFun();
      this.queryRecordByIdFun();
    },
    async queryByIdFun() {
      const res = await queryById(this.rowData.id);
      if (res.resultCode == 200) {
        this.formList.map(x => {
          x.initialValue = res.data[x.fieldName];
        });
      }
    },
    async queryRecordByIdFun() {
      const res = await queryRecordById(this.rowData.id);
      this.tableList = [];
      if (res.resultCode == 200) {
        this.tableList = res.data;
      }
    },
    closeDrawer() {
      this.$emit('close');
    },
    changeHandle(val) {
      this.saveData = val;
    },
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          placeholder: '',
          itemList: [
            { text: '在途车', value: 60401002 },
            { text: '库存车', value: 60401003 }
          ],
          disabled: true
        },
        // {
        //   type: 'SELECT',
        //   label: '是否首台',
        //   fieldName: 'isFirst',
        //   placeholder: '',
        //   itemList: this.createDictList('1004'),
        //   disabled: true
        // },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '申请单号',
          fieldName: 'applyNo',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '订单号',
          fieldName: 'orderNo',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '提报数量',
          fieldName: 'reportCount',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '品牌',
          fieldName: 'brandName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'seriesName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配置',
          fieldName: 'packageName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '选装',
          fieldName: 'optionName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '外饰',
          fieldName: 'colorName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '折后单价',
          fieldName: 'unitPrice',
          placeholder: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '申请状态',
          fieldName: 'checkStatus',
          placeholder: '',
          itemList: this.createDictList('6076'),
          disabled: true
        },
        {
          type: 'DATE',
          label: '提报时间',
          fieldName: 'checkReportDate',
          disabled: true,
          dateType: 'exactdate'
        },
        ,
        {
          type: 'DATE',
          label: '事业部审批时间',
          fieldName: 'checkDeptDate',
          disabled: true,
          dateType: 'exactdate'
        },
        ,
        {
          type: 'DATE',
          label: '销售部审批时间',
          fieldName: 'checkSalesDate',
          disabled: true,
          dateType: 'exactdate'
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          disabled: true,
          selfCols: 3,
          rows: 2
        }
      ];
    },
    createdLogTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '单据执行前状态',
          dataIndex: 'frontStatus',
          filterType: 'checkbox',
          filterItems: this.createDictList('6076'),
          render: props => {
            return <span>{this.createDictText(props.row.frontStatus, '6076')}</span>;
          }
        },
        {
          title: '单独执行后状态',
          dataIndex: 'returnStatus',
          filterType: 'checkbox',
          filterItems: this.createDictList('6076'),
          render: props => {
            return <span>{this.createDictText(props.row.returnStatus, '6076')}</span>;
          }
        },
        {
          title: '操作人员',
          dataIndex: 'createdByName'
        },
        {
          title: '操作时间',
          dataIndex: 'createdAt'
        },
        {
          title: '操作类型',
          dataIndex: 'operation'
        },
        {
          title: '审批意见',
          dataIndex: 'remark'
        }
      ];
    }
  }
};
</script>
